package model.agent.question

import java.util.ArrayList;

/**
 * 问题集类。输入问题集的字符串（字符串定义在excel表里），然后answer()
 * @author lee
 *
 */
class QuestionSet extends AbstractQuestion implements QuestionInterface{

	def static questionSep = "@"

	//单选分隔符
	def static singleSep = "/"

	//多选分隔符
	def static multiSep = "#"

	//权值分隔符
	def static valueSep = "="

	ArrayList<QuestionInterface> subQuestions = []
	
	String name = ""

	def QuestionSet(String qString){
		if(qString.trim() == "") return
		questionString = qString.trim().replace(" ","")

		def parts = questionString.split(questionSep)

		parts.each { String line ->
			
			if(line.contains(multiSep)){
				def msq = new MultiSelectQuestion(line)
				subQuestions.add(msq)
			}else if(line.contains(singleSep)){
				def ssq = new SingleSelectQuestion(line)
				subQuestions.add(ssq)
			}else{
				def ynq = new YesNoQuestion(line)
				subQuestions.add(ynq)
			}
		}
	}

	public float answer(AbstractList ans){
		def res = 0
		subQuestions.each{
			res += it.answer(ans)
		}
		lastResult = res
		return res
	}
	
	public float answer(String ans){
		def res = 0
		subQuestions.each{
			res += it.answer(ans)
		}
		lastResult = res
		return res
	}

	@Override
	public ArrayList<String> getOptions() {
		// TODO Auto-generated method stub
		ArrayList<String> options = []
		subQuestions.each { q ->
			options.add(q.options)
		}
		return options;
	}
	


}
